<template>
  <div>
    <div class="top">
      <div class="background">
        <img :src="coverImgUrl" />
      </div>
      <div class="message">
        <div class="back">
          <van-icon
            name="arrow-left"
            color="#fff"
            size="26px"
            style="margin: 5px 12px"
            @click="tap(index)"
          />
        </div>

        <div class="recommend">
          <div class="topShow">
            <div class="playCount">
              <van-icon name="eye-o" size="16px" />
              {{ (playCount / 10000).toFixed(2) }}万
            </div>
          </div>

          <div class="coverImgUrl">
            <img :src="coverImgUrl" />
          </div>

          <div class="name">
            {{ name }}
          </div>

          <div class="avatarUrl">
            <img :src="avatarUrl" />
            <div class="nickname">
              {{ nickname }}
            </div>
          </div>
        </div>

        <div class="title">歌曲列表</div>
      </div>
    </div>
    <!--加载中...-->
    <GlobalLoading v-if="isShowLoading"></GlobalLoading>
    <div class="music">
      <div class="left">
        <div
          class="number"
          :class="{ actived: currentIndex == index }"
          v-for="(item, index) in blockList"
          :key="index.Id"
        >
          <div class="order">{{ index + 1 }}</div>
        </div>
      </div>
      <div class="right">
        <GlobalSongs :blockList="blockList"></GlobalSongs>
      </div>
    </div>
  </div>
</template>
    
<script setup>
import GlobalSongs from "@/components/GlobalSongs.vue";
import GlobalLoading from "@/components/GlobalLoading.vue";
import { reactive, onMounted, ref } from "vue";
import { showToast } from "vant";
import { useMainStore } from "@/pinia/store.ts";
import router from "@/router/routes";
import { useRoute } from "vue-router";
import axios from "axios";
import { getPlaylistApi } from "@/request/api/home.ts";

const currentIndex = ref(0);
const mainStore = useMainStore();
const route = useRoute();
const isShowLoading = ref([]);

// 歌曲信息
const playCount = ref();
const coverImgUrl = ref();
const name = ref();
const avatarUrl = ref();
const nickname = ref();

// 音乐列表
const blockList = ref([]);
const value = ref("");



const tap = (index) => {
  console.log();
  router.go(-1);
};

// 获取首页编辑推荐中的id
function getQueryStringParams(url = window.location.href) {
  let queryParams = {};
  // 使用URLSearchParams解析当前页面URL中的查询字符串参数
  let urlParams = new URLSearchParams(url.split("?")[1]);
  for (const [key, value] of urlParams.entries()) {
    queryParams[key] = value;
  }
  return queryParams;
}
let id = getQueryStringParams();
console.log(id);

// 编辑推荐
const getPlaylist = async () => {
  const res = await getPlaylistApi(id);
  console.log("编辑推荐详情页");
  console.log(res);
  // 歌曲信息
  playCount.value = res.data.playlist.playCount;
  console.log(playCount.value);
  coverImgUrl.value = res.data.playlist.coverImgUrl;
  console.log(coverImgUrl.value);
  name.value = res.data.playlist.name;
  console.log(name.value);
  avatarUrl.value = res.data.playlist.creator.avatarUrl;
  console.log(avatarUrl.value);
  nickname.value = res.data.playlist.creator.nickname;
  console.log(nickname.value);

  // 音乐列表
  blockList.value = res.data.playlist.tracks;
  console.log(blockList.value);
};
onMounted(async () => {
  await getPlaylist();
  isShowLoading.value = false;
});
</script>
    
<style lang="scss" scoped>
.top {
  position: fixed;
  .background {
    position: relative;
    width: 375px;
    height: 226px;
    overflow: hidden;
    img {
      display: block;
      width: 100%;
      height: 100%;
    }
  }
  .background::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.5); /* 遮罩颜色和透明度 */
    pointer-events: none; /* 使得伪元素不影响鼠标事件 */
    backdrop-filter: blur(10px); /* 应用模糊效果 */
  }

  .message {
    position: fixed;
    top: 0;
    width: 100%;
    height: 226px;
    .back {
      width: 100%;
      height: 32px;
    }
    .recommend {
      position: relative;
      display: block;
      width: 135px;
      height: 174px;
      margin: 0 20px 0 16px;
      .topShow {
        position: absolute;
        top: 0;
        right: 0;
        background-image: linear-gradient(90deg, #0000, #0004);
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        .playCount {
          padding: 3px;
          color: #fff;
          font-size: 13px;
        }
      }
      .coverImgUrl {
        width: 136px;
        height: 136px;
        img {
          width: 136px;
          height: 136px;
        }
      }
      .name {
        position: absolute;
        top: 10px;
        left: 160px;
        width: 180px;
        color: #ffffff;
        font-size: 17px;
        font-weight: 700;
        display: block;
        overflow: hidden;
        line-height: 1.5;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
      }
      .avatarUrl {
        position: absolute;
        top: 80px;
        left: 156px;
        width: 200px;
        display: flex;
        flex-wrap: wrap;
        img {
          width: 30px;
          height: 30px;
          border-radius: 50%;
        }
        .nickname {
          color: #ffffffb3;;
          font-size: 15px;
          margin: 4px 8px;
        }
      }
    }
    .title {
      position: relative;
      display: flex;
      height: 20px;
      font-size: 12px;
      color: #666;
      padding: 0 15px;
      background-color: #eeeff0;
    }
  }
}

.music {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 100%;
  padding-top: 226px;
  .left {
    display: block;
    width: 10%;
    height: 100%;
    .number {
      .order {
        display: flex;
        height: 56px;
        justify-content: center;
        align-items: center;
        color: #999;
        font-size: 17px;
      }
    }
  }
  .right {
    display: block;
    width: 90%;
    height: 100%;
    padding-right: 10px;
  }
}
</style>